package entities;

import menu.Settings;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;

import util.Vector2D;

public class CannonEnemy extends Enemy {

	private float timeout;
	private float spawnTimer;

	public CannonEnemy(float frequency) throws SlickException {
		super("res/enemies/enemy06.png");
		image = image.getScaledCopy(90, 30);
		this.timeout = 1000.0f / frequency;
		maxHealth = (int) (15 * Settings.getfactor());
	}

	public void update(GameContainer gc, int delta) {
		super.update(gc, delta);
		if (spawnTimer <= 0) {
			try {
				AimingShot shot = new AimingShot("res/rocket.png", this, 3,
						new Vector2D(velocity.getX(), 20), level.getPlayer());
				shot.spawn(level, pos);
			} catch (SlickException e) {
				e.printStackTrace();
			}
			spawnTimer = timeout;
		}
		spawnTimer -= delta;
	}

	@Override
	public String getName() {
		return "Cannon Enemy";
	}

	public void reset() {
		super.reset();
		setVelocity(new Vector2D(-40.0f, 0.0f));
	}

}
